package com.mhc.suzuki.controller;

import com.mhc.haval.security.model.User;
import com.mhc.suzuki.bo.CreditQueryApplyBO;
import com.mhc.suzuki.constant.ErrorCodeEnum;
import com.mhc.suzuki.dal.mapper.ext.OrderAuditTaskExtMapper;
import com.mhc.suzuki.exception.SuzukiCommonException;
import com.mhc.suzuki.form.CreditQueryForm;
import com.mhc.suzuki.form.ExecutorForm;
import com.mhc.suzuki.service.RandomExecutorService;
import com.subaru.common.entity.BizResult;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * Created by HMJ on 2017/10/24.
 */
@Slf4j
@RestController
@RequestMapping(value = "/executor")
public class RandomExecutorController {
    @Autowired
    private RandomExecutorService randomExecutorService;


    @ApiOperation(value = "", httpMethod = "POST", notes = "")
    @RequestMapping(value = {"/randomExecutor"}, method = RequestMethod.POST)
    @ApiImplicitParam(name = "executorForm", value = "", required = false, paramType = "body", dataType = "ExecutorForm")
    public BizResult randomExecutor(@RequestBody ExecutorForm executorForm, @AuthenticationPrincipal User logedUser) {
        try {
            String person = randomExecutorService.randomExecutor(executorForm.getRoleCodeStr(),logedUser);
            return BizResult.create(person, ErrorCodeEnum.SUCCESS.getErrCode(), ErrorCodeEnum.SUCCESS.getErrMsg());
        } catch (SuzukiCommonException e) {
            log.error("randomExecutor SuzukiCommonException",e);
            return BizResult.create(e.getCode(),e.getMessage());
        }
    }

}
